//
//  main.c
//  模拟实现strncpy
//
//  Created by 卜绎皓 on 2022/5/11.
//

#include<stdio.h>
char* my_strncpy(char* dest, const char* src,size_t count)
{
    char* start = dest; // 记录目标字符串起始位置
    while (count && (*dest++ = *src++)) // 拷贝字符串
    {
        count--;
    }
    if (count) // 当count大于src的长度时，将补充空字符
    {
        while (--count)
        {
            *dest++ = '\0';
        }
    }
    return start;
}
int main()
{
    char arr1[] = "hello ";
    char arr2[] = " bit";
    my_strncpy(arr1, arr2, 5);
    printf("%s\n", arr1);
}


